<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>添加菜单</title>
    <script src="/plugin/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <link href="/plugin/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="/plugin/ligerUI/skins/Gray/css/all.css" rel="stylesheet"/>
    <link href="/css/form.css" rel="stylesheet"/>

    <script src="/plugin/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="/plugin/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

    <script src="/plugin/jquery/jquery.validate.js" type="text/javascript"></script>

    <style type="text/css">
        #Form label.error {
            color: Red;
        }
    </style>
</head>
<body style="margin: 10px;">
<form id="Form">
        <div class="formDiv">
            <div class="formLine">
                <div class="formInp">
                    <span>菜单名称：</span>
                    <input class="blue testTxt" placeholder="必填" required data-msg-required="菜单名称不能为空" type="text" name="menuName" value=""/>
                </div>
                <div class="formInp">
                    <span>菜单类型：</span>
                    <select class="blue testTxt" name="menuType">
                        <option value="0">按钮</option>
                        <option value="1">菜单</option>
                    </select>
                </div>
            </div>
        <div class="formLine">
            <div class="formInp">
                <span>打开方式：</span>
                <select class="blue testTxt" name="openType">
                    <option value="0">新页面</option>
                    <option value="1">模块窗口</option>
                </select>
            </div>
            <div class="formInp">
                <span>显示排序：</span>
                <select class="blue testTxt" name="sort">
                   <option  th:value="${currentSort}" th:text="${currentSort}"></option>
                   <option  th:each="sort : ${sorts}" th:value="${sort}" th:text="${sort}"></option>
                </select>
            </div>
        </div>

        <div class="formLine">
            <div class="formInp">
                <span>链接地址：</span>
                <input class="blue testTxt" placeholder="必填" required data-msg-required="链接地址不能为空" type="text" name="url" value=""/>
            </div>
            <div class="formInp">
                <span>是否可用：</span>
                <select class="blue testTxt" name="enabled">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
        </div>

        <div class="formLine">
            <div class="btn">
                <input type="submit" value="保存数据"/>
            </div>
        </div>
    </div>
    <input  type="hidden" name="deleted" value="0">
    <input class="blue testTxt1" type="hidden" name="creator"  th:value="${session.userSession.userName}"/>
    <input class="blue testTxt" type="hidden" name="parentId" th:value="${parentId}"/>
</form>
</body>
<script type="text/javascript">
    $(function(){
        $("#Form").validate({
            errorPlacement: function(error, element) {
                if (element.is(":input")){
                    error.appendTo(element.parent().parent());
                }else {
                    error.insertAfter(element);
                }
            },
            submitHandler: function() {
                sub();
            }
        });
    });
    function sub (){
        var data = $("#Form").serialize();
        $.ajax({
            type: 'POST',
            url: 'add',
            data: data,
            dataType: 'json',
            success: function(data){
                if(data.code==200){
                    parent.callBack();
                }else{
                    $.ligerDialog.error('保存失败');
                }
            },
            error:function(){
                $.ligerDialog.error('保存失败');
            }
        });
    }
</script>
</html>